using UnityEngine;

//破坏的墙代码
public class BrickWall : MonoBehaviour
{
    private float destructionTime = 0.5f;

    [Range(0f, 1f)]
    public float itemSpawnChance = 0.2f;//生成道具的概率
    public GameObject[] spawnableItems;

    private void Start()
    {
        Destroy(gameObject, destructionTime);
    }

    //销毁时按比例生成道具
    private void OnDestroy()
    {
        if (spawnableItems.Length > 0 && Random.value < itemSpawnChance)
        {
            int randomIndex = Random.Range(0, spawnableItems.Length);
            Instantiate(spawnableItems[randomIndex], transform.position, Quaternion.identity);
        }
    }
}

